Hi, in my Excel-Export I have to count the columns. I have set a userdefined view with function "setDefaultViewForModule()". The problem is, that I don't get the right count of columns! In my view I've set seven (attribute-)columns, but after my count script I get "col = 2". Where is the problem? I have attached my little script to count columns.
Thank you! tobi_mehrl - Wed Aug 05 05:02:30 EDT 2015 |
Re: Count columns in current module? First, your function is doing more than just counting the columns. Second, I'm not sure how that code is even compiling. Anyway, here is revised version of your function that should give you back the result you need, assuming that the correct View is loaded when the function is called.
int getNumColumns(Module mod)
{
Column c = null;
int count = 0;
if(null == mod)
return count;
for c in mod do
{
if(main(c) && doMain == mainIgnore))
continue;
count++;
}
return count;
}
|
Re: Count columns in current module? woodpryan - Wed Aug 05 11:49:47 EDT 2015 First, your function is doing more than just counting the columns. Second, I'm not sure how that code is even compiling. Anyway, here is revised version of your function that should give you back the result you need, assuming that the correct View is loaded when the function is called.
int getNumColumns(Module mod)
{
Column c = null;
int count = 0;
if(null == mod)
return count;
for c in mod do
{
if(main(c) && doMain == mainIgnore))
continue;
count++;
}
return count;
}
This looks good, but I think it wise to add a comment: // Counts the number of columns in the current view of the specified module. You cannot count columns in an unloaded view. -Louie |
Re: Count columns in current module? woodpryan is correct if you are just counting currently displayed columns in the module. I'm guessing you have failed to load your default view for that module; perhaps you have an additional default view for your user. setDefaultViewForModule() and setDefaultViewForUser() set the default but do not load that view. I think loading the view is
You may also have a "current" module issue. add this before your column loop:
You really should use Module handles:
This code seems to set row 1 in Excel with column headers. I doesn't seem right to bypass a column with a null title, since when you loop through the objects those column values will be displayed, and your header row won't match the data rows. |
Re: Count columns in current module? llandale - Thu Aug 06 12:12:50 EDT 2015 woodpryan is correct if you are just counting currently displayed columns in the module. I'm guessing you have failed to load your default view for that module; perhaps you have an additional default view for your user. setDefaultViewForModule() and setDefaultViewForUser() set the default but do not load that view. I think loading the view is
You may also have a "current" module issue. add this before your column loop:
You really should use Module handles:
This code seems to set row 1 in Excel with column headers. I doesn't seem right to bypass a column with a null title, since when you loop through the objects those column values will be displayed, and your header row won't match the data rows. Hi, I think my problem is the way I enable my view! Can anyone show me the way to enable a view?
I have changed my code. I have changed the count function and I have inserted the "load view", but columns won't be count correctly. In my used view I have seven columns but my script only counts 2 of them!
I iterate over modules (for i in f do) in a folder. If the for-loop has opened a module, the function setCell(...) copies the content from Doors to Excel, but to copy the content I need the "current" column, better, I need all column. In function checkViewAvailability() (as statement in if!) I will set view with setDefaultViewForModule()-function depending of content of variable "myMainView" and the current module. Variable myMainView is loaded with statement get mainView which is loaded from a GUI.
I have attached the functions. Can anyone help me? Attachments setCell.dxl checkViewAvailability.dxl functionSnip.dxl |
Re: Count columns in current module? tobi_mehrl - Mon Aug 10 03:50:56 EDT 2015 Hi, I think my problem is the way I enable my view! Can anyone show me the way to enable a view?
I have changed my code. I have changed the count function and I have inserted the "load view", but columns won't be count correctly. In my used view I have seven columns but my script only counts 2 of them!
I iterate over modules (for i in f do) in a folder. If the for-loop has opened a module, the function setCell(...) copies the content from Doors to Excel, but to copy the content I need the "current" column, better, I need all column. In function checkViewAvailability() (as statement in if!) I will set view with setDefaultViewForModule()-function depending of content of variable "myMainView" and the current module. Variable myMainView is loaded with statement get mainView which is loaded from a GUI.
I have attached the functions. Can anyone help me? I don't think you want to set the default view for the module, I think you need to load the view:
The "default" view is what gets loaded by default the NEXT time you open the module. -Louie |
Re: Count columns in current module? llandale - Mon Aug 10 15:05:06 EDT 2015 I don't think you want to set the default view for the module, I think you need to load the view:
The "default" view is what gets loaded by default the NEXT time you open the module. -Louie Hi, is it possible that you have a mistake in your function? You have four opening braces but only three closing braces. I have now coded load(view(item(fullName(cM))), mV) but I get a failure in the window:
-E- DXL: <Line:466> Falsche Argumente für Funktion (view) I have also read in DXL reference. There is to read, that the load-function is depending on first parameter Module m and second parameter View v. With your code, the first parameter is from type view? Do you know what I mean? |
Re: Count columns in current module? You may find this code useful:
/* Function: loadViewInvisible(string, &Module)
Purpose: Loads the specified view without visibly opening the specified Module
if the view and Module exist. The function is necessary because DXL
does not provide a way of opening a view without doing so visibly.
This function changes the default view for the user, loads the Module,
and then changes the default view back.
If the view name passed to the function is Standard view, there needs to
not be any handles to this Module because this function cannot invisibly load
the standard view.
Parameters: the View name, a reference to the Module
Return: success
*/
bool loadViewInvisible(string vName, Module &mod)
{
string defViewName = null;
string err = null;
string modName = null;
modName = fullName(mod);
defViewName = getDefaultViewForUser(mod);
err = setDefaultViewForUser(mod, vName);
if(null != err)
{
logError("Could not set new default view: " vName " for Module: " modName);
logMessage("setDefualtViewForUser returned the following error: \n" err);
return false;
}
if(null == modName)
{
logError("Could not retrieve the Module Name from the Module passed to loadViewInvisible");
return false;
}
mod = read(modName, false);
if(null == defViewName)
clearDefaultViewForUser(mod)
else
err = setDefaultViewForUser(mod, defViewName);
if(null != err)
{
logError("Changed default view for user on Module " modName " and failed to change it back.");
logMessage("setDefaultViewForUser returned the following error: \n" err);
}
logMessage("Loaded view " currentView(mod) " for Module " modName);
return true;
}
Either write yourself a logMessage(string) and logError(string) function or change the calls to those functions to called to the print(string) function instead. |